package com.example.myblog.mapper;

import com.example.myblog.entity.ArticleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    @Select("select count(*) from articleinfo where uid = #{uid}")
    int getArtCntByUid(Integer uid);//通过用户id查询发布文章数

    @Select("select * from articleinfo where uid = #{uid}")
    List<ArticleInfo> getMyArtList(Integer uid);//获取用户个人文章列表信息

    @Select("select * from articleinfo limit #{psize} offset #{offsize}")
    List<ArticleInfo> getListByPage(Integer psize,
                                    Integer offsize);//分页获取文章信息列表

    @Delete("delete from articleinfo where id = #{id} and uid = #{uid}")
    int del(Integer id, Integer uid);//通过文章id和用户id联合查询删除文章

    @Insert("insert into articleinfo(title, content, uid) values (#{title}, #{content}, #{uid})")
    int add(ArticleInfo articleInfo);//增添文章

    @Update("update articleinfo set title=#{title}, content=#{content}, updatetime=#{updatetime} where id = #{id} and uid = #{uid}")
    int update(ArticleInfo articleInfo);//文章更新

    @Select("select * from articleinfo where id = #{id}")
    ArticleInfo getArtDetail(Integer id);//通过文章id查询文章具体详情

    @Update("update articleinfo set rcount=rcount + 1 where id = #{id}")
    int incrReadCnt(Integer id);//文章阅读次数增长

    @Select("select count(*) from articleinfo")
    int getCount();//获取文章数
}
